//
//  YYJLRuleController.m
//  YuanyangJinlou
//
//  Created by mac004 on 2017/1/5.
//  Copyright © 2017年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLRuleController.h"
#import "YYJLLevelCell.h"
#import "YYJLRankRuleCell.h"
@interface YYJLRuleController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSMutableArray * _levelArr;//等级数组
    NSMutableArray * _rankArr;//积分数组
}
@end

@implementation YYJLRuleController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController  setNavigationBarHidden:NO animated:NO];
    _levelArr=[[NSMutableArray alloc]initWithObjects:@[@"对应等级",@"对应积分"], @[@"1",@"0"],@[@"2",@"100"],@[@"3",@"300"],@[@"4",@"600"],@[@"5",@"1000"],@[@"6",@"1500"],@[@"7",@"2000"],@[@"8",@"3000"],@[@"9",@"5000"],@[@"10",@"8000"],@[@"11",@"12000"],@[@"12",@"150000"],nil];
    _rankArr=[[NSMutableArray alloc]initWithObjects:@[@"加分项目",@"加分分值"],@[@"新手首次登陆",@"+5"],@[@"签到",@"详积分说明"],@[@"学习",@"视不同的课程而定"],@[@"趣味答题",@"每过一关+5"],@[@"发帖",@"+2"],@[@"获赞20及以上",@"+2"],@[@"发表新品评论",@"+2"],@[@"APP使用时间",@"详积分说明"], nil];
    [self setTitleView:@"积分规则"];
    [self setBackItem];
    [self creatUI];
}

-(void)creatUI{
    UIScrollView*_scrollView=[[UIScrollView alloc]initWithFrame:self.view.bounds];
    _scrollView.backgroundColor=UIColorFromHex(0xf7f7f7);
    [self.view addSubview:_scrollView];
    //1 头
    UIImageView * headerImgview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160*PER_HEIGHT)];
    headerImgview.image=[UIImage imageNamed:@"bg_jifenguize"];
    [_scrollView addSubview:headerImgview];
    
    UILabel * lable1=[MyControl createLabelWithFrame:CGRectMake(0, 35*PER_HEIGHT, SCREEN_WIDTH, 16*PER_HEIGHT) Font:16 Text:@"商学院用户等级积分说明" Color:WHITE_COLOR];
    lable1.textAlignment=NSTextAlignmentCenter;
    [headerImgview addSubview:lable1];;
    
    UILabel * lable2=[MyControl createLabelWithFrame:CGRectMake(0,lable1.bottom+ 20*PER_HEIGHT, SCREEN_WIDTH, 12*PER_HEIGHT) Font:12 Text:@"商学院用户等级积分包括积分、等级两部分。" Color:WHITE_COLOR];
    lable2.textAlignment=NSTextAlignmentCenter;
    [headerImgview addSubview:lable2];;
    
    UILabel * lable3=[MyControl createLabelWithFrame:CGRectMake(0,lable2.bottom+4*PER_HEIGHT, SCREEN_WIDTH, 12*PER_HEIGHT) Font:12 Text:@"用户可通过应用日常操作及贡献内容获取积分。" Color:WHITE_COLOR];
    lable3.textAlignment=NSTextAlignmentCenter;
    [headerImgview addSubview:lable3];;
    
    UILabel * lable4=[MyControl createLabelWithFrame:CGRectMake(0,lable3.bottom+4*PER_HEIGHT, SCREEN_WIDTH, 12*PER_HEIGHT) Font:12 Text:@"用户等级由积分决定。" Color:WHITE_COLOR];
    lable4.textAlignment=NSTextAlignmentCenter;
    [headerImgview addSubview:lable4];;
    
    //2 等级对照表
    UIImage* bgTable=[UIImage imageNamed:@"bg_beijing"];
    UIImageView * tableView =[[UIImageView alloc]initWithFrame:CGRectMake(90*PER_WIDTH, headerImgview.bottom+25*PER_HEIGHT, 195*PER_WIDTH, 44*PER_HEIGHT)];
    tableView.image=bgTable;
    [_scrollView addSubview:tableView];
    UILabel * levelLabel=[MyControl createLabelWithFrame:CGRectMake(0, 15*PER_HEIGHT, 195*PER_WIDTH, 14*PER_HEIGHT) Font:14 Text:@"等级及所需积分对照表" Color:WHITE_COLOR];
    levelLabel.textAlignment=NSTextAlignmentCenter;
    [tableView addSubview:levelLabel];
    
    UIImage * levelImg=[UIImage imageNamed:@"ico_dengji"];
    UIImageView * levelView =[[UIImageView alloc]initWithFrame:CGRectMake(50*PER_WIDTH, tableView.top+4*PER_HEIGHT, levelImg.size.width*PER_WIDTH, levelImg.size.height*PER_HEIGHT)];
    levelView.image=levelImg;
    [_scrollView addSubview:levelView];
    
    UITableView* levelTableView =[[UITableView alloc]initWithFrame:CGRectMake(12*PER_WIDTH, tableView.bottom+10*PER_HEIGHT, SCREEN_WIDTH-24*PER_WIDTH, 496*PER_HEIGHT) style:UITableViewStylePlain];
    levelTableView.tag=1;
    levelTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    levelTableView.dataSource=self;
    levelTableView.delegate=self;
    [_scrollView addSubview:levelTableView];
    
    //3 积分对照表
    UIImageView * tableView1 =[[UIImageView alloc]initWithFrame:CGRectMake(90*PER_WIDTH, levelTableView.bottom+25*PER_HEIGHT, 195*PER_WIDTH, 44*PER_HEIGHT)];
    tableView1.image=bgTable;
    [_scrollView addSubview:tableView1];
    UILabel * levelLabel1=[MyControl createLabelWithFrame:CGRectMake(0, 15*PER_HEIGHT, 195*PER_WIDTH, 14*PER_HEIGHT)  Font:14 Text:@"积分规则对照表" Color:WHITE_COLOR];
    levelLabel1.textAlignment=NSTextAlignmentCenter;
    [tableView1 addSubview:levelLabel1];
    
    UIImage * levelImg1=[UIImage imageNamed:@"ico_jifen-0"];
    UIImageView * levelView1 =[[UIImageView alloc]initWithFrame:CGRectMake(50*PER_WIDTH, tableView1.top+4*PER_HEIGHT, levelImg1.size.width*PER_WIDTH, levelImg1.size.height*PER_HEIGHT)];
    levelView1.image=levelImg1;
    [_scrollView addSubview:levelView1];
    UITableView* rankTableView =[[UITableView alloc]initWithFrame:CGRectMake(12*PER_WIDTH, tableView1.bottom+10*PER_HEIGHT, SCREEN_WIDTH-24*PER_WIDTH, 384*PER_HEIGHT) style:UITableViewStylePlain];
    rankTableView.tag=2;
    rankTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    rankTableView.dataSource=self;
    rankTableView.delegate=self;
    [_scrollView addSubview:rankTableView];

    //4 说明
    UILabel * instructionLb =[MyControl createLabelWithFrame:CGRectMake(12*PER_WIDTH,rankTableView.bottom+15*PER_HEIGHT, 80*PER_WIDTH, 14*PER_HEIGHT) Font:14 Text:@"积分说明" Color:FEELT_COLOR];
    [_scrollView addSubview:instructionLb];
    
    UIView * round1=[[UIView alloc]initWithFrame:CGRectMake(12*PER_WIDTH, instructionLb.bottom+12*PER_HEIGHT, 15*PER_WIDTH, 15*PER_WIDTH)];
    round1.layer.cornerRadius=round1.height/2;
    round1.layer.masksToBounds=YES;
    round1.backgroundColor=FEELT_COLOR;
    [_scrollView addSubview:round1];
    UILabel*num1=[MyControl createLabelWithFrame:round1.bounds Font:10 Text:@"1" Color:WHITE_COLOR];
    num1.font=[UIFont fontWithName:HLT size:10];
    num1.textAlignment=NSTextAlignmentCenter;
    [round1 addSubview:num1];
    UILabel*contenLb1=[MyControl createLabelWithFrame:CGRectMake(round1.right+6*PER_WIDTH, instructionLb.bottom+12*PER_HEIGHT, SCREEN_WIDTH-51*PER_WIDTH, 72*PER_HEIGHT) Font:12 Text:@"签到:已一周7天为签到周期。连续签到一天得1积分,2天得2积分,以此递增,连续签到第7天积分翻倍即14分。连续签到7天后,又重新计算签到周期,即又从1积分开始累积递增。周期内中断签到,再开始签到则算第一天。" Color:FEELT_COLOR];
    contenLb1.numberOfLines=0;
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:contenLb1.text];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:8*PER_HEIGHT];
    paragraphStyle1.alignment = contenLb1.textAlignment;
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [contenLb1.text length])];
    [contenLb1 setAttributedText:attributedString1];
    [_scrollView addSubview:contenLb1];
    
    UIView * round2=[[UIView alloc]initWithFrame:CGRectMake(12*PER_WIDTH, contenLb1.bottom+12*PER_HEIGHT, 15*PER_WIDTH, 15*PER_WIDTH)];
    round2.layer.cornerRadius=round1.height/2;
    round2.layer.masksToBounds=YES;
    round2.backgroundColor=FEELT_COLOR;
    [_scrollView addSubview:round2];
    UILabel*num2=[MyControl createLabelWithFrame:round1.bounds Font:10 Text:@"2" Color:WHITE_COLOR];
    num2.font=[UIFont fontWithName:HLT size:10];
    num2.textAlignment=NSTextAlignmentCenter;
    [round2 addSubview:num2];
    UILabel*contenLb2=[MyControl createLabelWithFrame:CGRectMake(round2.right+6*PER_WIDTH, contenLb1.bottom+12*PER_HEIGHT, SCREEN_WIDTH-51*PER_WIDTH, 72*PER_HEIGHT) Font:12 Text:@"签到:已一周7天为签到周期。连续签到一天得1积分,2天得2积分,以此递增,连续签到第7天积分翻倍即14分。连续签到7天后,又重新计算签到周期,即又从1积分开始累积递增。周期内中断签到,再开始签到则算第一天。" Color:FEELT_COLOR];
    contenLb2.numberOfLines=0;
    NSMutableAttributedString * attributedString2 = [[NSMutableAttributedString alloc] initWithString:contenLb2.text];
    NSMutableParagraphStyle * paragraphStyle2 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle2 setLineSpacing:8*PER_HEIGHT];
    paragraphStyle2.alignment = contenLb2.textAlignment;
    [attributedString2 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle2 range:NSMakeRange(0, [contenLb2.text length])];
    [contenLb2 setAttributedText:attributedString2];
    [_scrollView addSubview:contenLb2];
 
    
    _scrollView.contentSize=CGSizeMake(0, 1333*PER_HEIGHT);
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag==1) {
        return 13;
    }else{
        return 9;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag==1) {
        YYJLLevelCell*cell1=[tableView dequeueReusableCellWithIdentifier:@"cell1"];
        if (!cell1) {
            cell1=[[YYJLLevelCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"];
                 cell1.selectionStyle=UITableViewCellSelectionStyleNone;
        }
   
        cell1.ruleArr=_levelArr[indexPath.row];
        if (indexPath.row==0) {
            cell1.backgroundColor=TINK_COLOR;
        }else{
            cell1.backgroundColor=[UIColor whiteColor];
        }
        return cell1;
    }
    else{
        YYJLRankRuleCell*cell2=[tableView dequeueReusableCellWithIdentifier:@"cell2"];
        if (!cell2) {
            cell2=[[YYJLRankRuleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell2"];
             cell2.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        cell2.ruleArr=_rankArr[indexPath.row];
        if (indexPath.row==0) {
            cell2.backgroundColor=TINK_COLOR;
        }else{
            cell2.backgroundColor=[UIColor whiteColor];
        }

        return cell2;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag==1) {
        if (indexPath.row==0) {
            return 40*PER_HEIGHT;
        }else{
            return 38*PER_HEIGHT;
        }
    }else{
        if (indexPath.row==0) {
            return 40*PER_HEIGHT;
        }else{
            return 38*PER_HEIGHT;
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
